package ar.edu.unsam.algo3.plantasvszombies.wicket;

import ar.edu.unsam.algo3.plantasvszombies.dominio.Jardin;
import ar.edu.unsam.algo3.plantasvszombies.ui.ApplicationModels.JardinAppModel;
import ar.edu.unsam.algo3.plantasvszombies.wicket.JardinPage;
import ar.edu.unsam.algo3.plantasvszombies.wicket.MainPage;
import com.google.common.base.Objects;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.PropertyModel;
import org.eclipse.xtext.xbase.lib.Extension;
import org.eclipse.xtext.xbase.lib.Functions.Function0;
import org.eclipse.xtext.xbase.lib.ObjectExtensions;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure0;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.uqbar.wicket.xtend.WicketExtensionFactoryMethods;
import org.uqbar.wicket.xtend.XButton;

@SuppressWarnings("all")
public class HomePage extends MainPage {
  @Extension
  private WicketExtensionFactoryMethods _wicketExtensionFactoryMethods = new Function0<WicketExtensionFactoryMethods>() {
    public WicketExtensionFactoryMethods apply() {
      WicketExtensionFactoryMethods _wicketExtensionFactoryMethods = new WicketExtensionFactoryMethods();
      return _wicketExtensionFactoryMethods;
    }
  }.apply();
  
  private String _nombreJugador;
  
  public String getNombreJugador() {
    return this._nombreJugador;
  }
  
  public void setNombreJugador(final String nombreJugador) {
    this._nombreJugador = nombreJugador;
  }
  
  public HomePage() {
    XButton _xButton = new XButton("comenzar");
    final XButton button = _xButton;
    final Procedure0 _function = new Procedure0() {
      public void apply() {
        String _nombreJugador = HomePage.this.getNombreJugador();
        boolean _notEquals = (!Objects.equal(_nombreJugador, null));
        if (_notEquals) {
          JardinAppModel _jardinApp = HomePage.this.getJardinApp();
          Jardin _jardin = _jardinApp.getJardin();
          String _nombreJugador_1 = HomePage.this.getNombreJugador();
          _jardin.setJugador(_nombreJugador_1);
          JardinAppModel _jardinApp_1 = HomePage.this.getJardinApp();
          JardinPage _jardinPage = new JardinPage(_jardinApp_1);
          HomePage.this.setResponsePage(_jardinPage);
        } else {
          HomePage.this.error("Si no ingresas tu nombre no te dejare jugar!!!");
        }
      }
    };
    button.setOnClick(_function);
    this.info("Ingresa tu nombre para iniciar el juego");
    Form<Object> _form = new Form<Object>("formJuego");
    final Procedure1<Form<Object>> _function_1 = new Procedure1<Form<Object>>() {
      public void apply(final Form<Object> it) {
        PropertyModel<String> _propertyModel = new PropertyModel<String>(HomePage.this, "nombreJugador");
        TextField<String> _textField = new TextField<String>("nombreJugador", _propertyModel);
        HomePage.this._wicketExtensionFactoryMethods.addChild(it, _textField);
        HomePage.this._wicketExtensionFactoryMethods.addChild(it, button);
        FeedbackPanel _feedbackPanel = new FeedbackPanel("feedbackPanel");
        HomePage.this._wicketExtensionFactoryMethods.addChild(it, _feedbackPanel);
      }
    };
    Form<Object> _doubleArrow = ObjectExtensions.<Form<Object>>operator_doubleArrow(_form, _function_1);
    this._wicketExtensionFactoryMethods.addChild(this, _doubleArrow);
  }
}
